﻿using System;
using System.Collections.Generic;
using System.Text;
using TomShane.Neoforce.Controls;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace Warlock.Menu
{
    /// <summary>
    /// Ein Button mit leuchtendem Rahmen
    /// </summary>
    class MenuItemButton
    {
        #region Properties
        public Button Button { get; private set; }
        public ImageBox Border { get; private set; }
        /// <summary>
        /// Die Position des eigentlichen Buttons
        /// </summary>
        public Vector2 Position
        {
            get
            {
                return new Vector2(Button.Left, Button.Top);
            }
            set
            {
                Button.Left = (int)value.X;
                Button.Top = (int)value.Y;
                UpdateBorder();
            }
        }
        #endregion

        Texture2D activated;
        Texture2D deactivated;

        public MenuItemButton()
        {
        }
        /// <summary>
        /// Initialisiert das Control
        /// </summary>
        /// <param name="manager"></param>
        /// <param name="content"></param>
        public void Init(Manager manager, ContentManager content)
        {
            LoadContent(content);

            Button = new Button(manager);
            Button.Init();
            Button.Width = 594;
            Button.Height = 86;
            Button.MouseOver += new MouseEventHandler(Button_MouseOver);
            Button.MouseOut += new MouseEventHandler(Button_MouseOut);

            Border = new ImageBox(manager);
            Border.Image = deactivated;

            UpdateBorder();
        }
        /// <summary>
        /// Laedt die Bilder,
        /// wird von Init aufgerufen.
        /// </summary>
        /// <param name="content">Ein Content-Manager</param>
        void LoadContent(ContentManager content)
        {
            activated = content.Load<Texture2D>("Resources\\Menu\\MenuItemSelected");
            deactivated = content.Load<Texture2D>("Resources\\Menu\\MenuItemUnselected");
        }
        void Button_MouseOver(object sender, MouseEventArgs e)
        {
            if (activated == null || deactivated == null)
                throw new Exception("MenuItem hat keine Rahmenbilder geladen. Eventuell vergessen menuItem.LoadContent() aufzurufen?");
            Border.Image = activated;
        }
        void Button_MouseOut(object sender, MouseEventArgs e)
        {
            if (activated == null || deactivated == null)
                throw new Exception("MenuItem hat keine Rahmenbilder geladen. Eventuell vergessen menuItem.LoadContent() aufzurufen?");
            Border.Image = deactivated;
        }
        /// <summary>
        /// Passt die Position des Rahmens an die Position des Buttons an
        /// </summary>
        void UpdateBorder()
        {
            Border.Left = Button.Left - 79;
            Border.Top = Button.Top - 48;
        }
    }
}